Skip to content

fix(hermes): keep recognized credentials out of the pre-compression checkpoint - #2821

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/hermes-precompress-privacy
Nov 25, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/hermes-precompress-privacy

Conversation

@Fengzdadi

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Part of #2250. Builds on #2703 (merged), which applied the shared automatic prompt privacy rule to the Hermes recall query, completed-turn capture and evaluation trace; this PR extends it to the Hermes pre-compression checkpoint.

Rationale for this change

Hermes pre-compression capture (on_pre_compress) redacted each message only with the plugin's own redact_secrets. That rule recognizes fewer credential formats than the shared rule in src/powercontext_integration_lifecycle/prompt_privacy.py, and its assignment pattern consumes the scheme word of an Authorization header. As a result:

  • Authorization: Bearer <token> reached the Server as [REDACTED] <token>;
  • DB_PASSWORD=<value> and other prefixed key names reached it unchanged.

A turn that completed-turn capture skips could therefore still reach the Server, with its credential, in a pre-compression window, and hermes.md documented that gap.

What changes are included in this PR?

Behavior

  • Each user/assistant message in the checkpoint window is redacted with the shared rule (with the configured Authorization value) and then with the plugin's own rule. This is the same composition, in the same order, that the evaluation trace uses since fix(integrations): keep recognized credentials out of automatic recall and capture in in-process adapters #2703.
  • A message with a recognized credential stays in the window, with the credential replaced by [REDACTED]. It is not left out.
    • The checkpoint commits the same messages as before, so a credential in the transcript never makes a required checkpoint fail and never blocks compression.
    • Fingerprints still hash the original messages, so Source IDs, overlap detection and the captured snapshot are unchanged.
    • The coverage declaration is unchanged. hermes-precompress-text.v1 already defines its projection as the window after secret redaction, and coverage reports only capacity losses.
  • Unchanged:
    • system/tool message exclusion;
    • the 30,000-character limit;
    • the evidence_messages preference;
    • checkpoint transitions.

Leaving flagged messages out, as completed-turn capture does with whole turns, would break the existing checkpoint contract. test_pre_compress_filters_roles_and_redacts_secrets and the Hermes boundary conformance case (test_private_display_fields_do_not_cross_adapter_boundaries, on_pre_compress) both require that a message holding api_key=<value> keeps its other text with [REDACTED] in place of the value.

Code

  • helpers.precompress_entries takes the redaction function as a keyword argument. It defaults to redact_secrets, so the helper's behavior on its own is unchanged.
  • provider.py renames _trace_redaction to _redact_credentials, now used by the trace and the checkpoint, and passes it to precompress_entries.

Tests (tests/integrations/test_hermes_provider.py, next to the existing pre-compression tests)

  • Every case in tests/fixtures/automatic_prompt_privacy.json runs through a required checkpoint, as a user message and as an assistant message, after a clean user message. The configured Authorization value is set for the known-Server-token case.
    • Sensitive cases: the checkpoint commits both messages with complete coverage, and no value marker appears in the captured content, its metadata or any log record.
    • Ordinary cases: the content is exactly what the plugin rule alone produces, as before.
  • A required checkpoint whose window holds Authorization: Bearer <value> commits once, does not raise, is not retried on the next call with the same window, and a later window captures only its new message.

Docs

  • docs/{en,zh}/docs/integrations/hermes.md: the "Before compression" row and the paragraph after the table describe the shared-rule redaction and that the message stays in the window.
  • docs/{en,zh}/docs/integrations/index.md: "Automatic prompt privacy" no longer says that Hermes pre-compression capture keeps only its own redaction.

Are there any user-facing changes?

Yes, for Hermes with capture_pre_compress=true:

  • Pre-compression Sources no longer contain credentials that the shared rule recognizes. This includes the configured Authorization value, Bearer values after an Authorization: header, and prefixed key names such as DB_PASSWORD=.
  • Messages with other text are still captured, with the credential replaced.

Capture defaults, checkpoint behavior and Source IDs are unchanged. Sources already stored are not changed. No API, coverage or persisted-format changes.

A window that an earlier plugin version already stored, and that is retried unchanged after the upgrade, keeps its Source ID but now carries different content. The Server can then reject the retry as a conflict, and a required checkpoint fails for that attempt. The next window has new messages and a new Source ID.

How was this change tested?

All commands ran offline (UV_OFFLINE=1 UV_NO_SYNC=1) on commit 90668d5, which is based on master eb695a1.

  • uv run pytest tests/integrations/test_hermes_provider.py: 317 passed, including the 133 new tests (66 cases × 2 roles, plus the required-checkpoint test). Without the source change, the new tests failed 85 of 133: every sensitive case that the plugin rule alone misses (42 cases × 2 roles) and the required-checkpoint test. The 11 sensitive cases that the plugin rule already caught and all 13 ordinary cases passed. This was measured on 90668d5 with provider.py and helpers.py restored to master.
  • uv run pytest tests/integrations/test_hermes_provider.py tests/test_hermes_cli.py tests/integration_conformance tests/test_automatic_prompt_privacy.py -k "hermes or Hermes": 461 passed, 1 skipped.
  • python scripts/generate_integration_lifecycle.py --check and prek run --files <changed files> pass.
  • make unit-test: 10,412 passed, 449 skipped, 13 failed, 120 errors, none in a changed file. Running those 133 failing and erroring test IDs on unmodified master eb695a1 gives the same 13 failures and 120 errors.
    • The 120 errors (test_hook_characterization, test_session_start_shells, test_user_prompt_submit_shells) come from a uv sync in their fixtures that cannot complete offline, and the test_system_cli Codex setup failure also needs packages that are not cached locally.
    • The other 12 failures are 8 in test_jev_rerank_comparison and 4 in test_ci_installation_roles.
  • Not run against a real Hermes host or a real Server, and no real credentials were used. The fake client records only what the provider sends.

AI usage statement

Claude Code (Claude Opus 5.5) wrote the change, the tests and this description, ran the checks above, and reviewed its own diff. No human has reviewed it yet.

…heckpoint

Pre-compression capture redacted each message only with the plugin's own
rule, so an Authorization Bearer value or a prefixed key name such as
DB_PASSWORD= reached the Server. Each message is now redacted with the shared
prompt-privacy rule and then the plugin's rule, the same order the evaluation
trace uses. The message stays in the window, so a credential never fails a
required checkpoint, and fingerprints, Source IDs and coverage are unchanged.

@NeverENG NeverENG left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 90668d5. No blocking findings in the checkpoint redaction change: shared credential scrubbing precedes plugin redaction, while the original-message fingerprints preserve overlap detection and checkpoint retries.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 90668d5. No blocking findings. Applying the shared scrubber before plugin redaction closes the pre-compression credential leak while preserving original-message fingerprints, overlap detection, and required-checkpoint behavior. No new database tables or external interfaces; the optional helper callback is internal. Merge score: 90/100. Local focused validation reached 461 passed and 1 skipped after rerunning a Server startup timeout and fixing review-checkout Git metadata. Real Hermes host acceptance was not exercised.

@hidb4ai
hidb4ai merged commit 537031d into oceanbase:master Nov 25, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants